/**
 *
 * MobileLib   
 * LoginActivityf.java
 * Dec 27, 2011
 * @author qidiven
 *
 */
package com.ustc.mobilelib.view;

import android.app.Activity;
import android.os.Bundle;
import android.view.Gravity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.ustc.diven.model.R;
import com.ustc.mobilelib.control.RequestHelper;
import com.ustc.mobilelib.model.DataCenter;

public class LoginActivity extends Activity{

	private Button loginBtn = null;
	private EditText userIDEdit = null;
	private EditText userPWDEdit = null;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.login);
		init();
	}
	
	private void init()
	{
		loginBtn = (Button) findViewById(R.id.login);
		userIDEdit = (EditText) findViewById(R.id.userIDEdit);
		userPWDEdit = (EditText) findViewById(R.id.userPWDEdit);
		
		loginBtn.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				String userID = userIDEdit.getText().toString();
				String userPWD = userPWDEdit.getText().toString();
				if(!userID.equals("")&&!userPWD.equals(""))
				{
					int resultID = RequestHelper.postLoginMsg(userID, userPWD);
					if(0 == resultID)
					{
						DataCenter.getInstance().setHasLogin(true);
						
					}else if(-1 == resultID)
					{
						DataCenter.getInstance().setHasLogin(false);
					}
					else 
					{
						//Toast info
					}
				}
			}
		});
		
	}

}
